﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using System.Diagnostics;
using System.Data.SqlClient;


//using MyWeb.DataAccessHelper;
//namespace MyWeb.DataAccessLayer
//{
public class seleData
{
    Datacon dataconn = new Datacon();
    Datacommand datacom = new Datacommand();

    public string chashuifei(string weixinhao)//查找水费记录
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select  * from yongshui where weixinghao='" + weixinhao + "' order by cbrq desc";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);



        while (reader.Read())
        {
            @jieguo = jieguo + "月份：" + reader["yuefen"].ToString() + "\n"
               + "用户编号：" + reader["hbh"].ToString() + "\n"
                        + "用户名：" + reader["hm"].ToString() + "\n"
                        + "用水性质：" + reader["yslbbh"].ToString() + "\n"
                        + "水表口径：" + reader["sbkj"].ToString() + "\n"
                        + "本月行度：" + reader["byxd"].ToString() + "\n"
                        + "本月水量：" + reader["bysl"].ToString() + "\n"
                        + "基本水费：" + reader["jbsf"].ToString() + "\n"
                        + "附加费：" + reader["fjf"].ToString() + "\n"
                        + "污处费：" + reader["wcf"].ToString() + "\n"
                        + "垃圾费：" + reader["ljf"].ToString() + "\n"
                        + "合计金额：" + reader["hj"].ToString() + "\n"
                        + "抄表日期：" + reader["cbrq"].ToString() + "\n"
                        + "收款情况：" + reader["sff"].ToString() + "\n"
                        + "缴费日期：" + reader["jfrq"].ToString() + "\n"
                        + "状态：" + reader["ztbh"].ToString() + "\n\n";



        }
        cn.Close();
        return jieguo;
    }
    public string chabszn(string chaxunwenzi, string urltou)//查找办事指南
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select  count(*) as ts from YeWuZiLiao where isnull(parentID,0)>0 and mingcheng like '%" + chaxunwenzi + "%'";
        SqlCommand myCommand = new SqlCommand(sql, cn);
        dataconn.WriteLogclass(sql);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);
        if (reader.Read())
        {
            if (Convert.ToInt32(reader["ts"].ToString()) == 1000000)//如果只是一条，直接返回记录
            {
                reader.Close();
                cn.Close();
                cn.Open();
                sql = "select  *  from YeWuZiLiao where isnull(parentID,0)>0 and mingcheng like '%" + chaxunwenzi + "%'";
                myCommand.CommandText = sql;
                reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())//判断是否字数在限制内，如果是直接返回
                {
                    @jieguo = jieguo + reader["mingcheng"].ToString() + "\n\n" + reader["neirong"].ToString() + "\n\n";
                }
            }
            else
            {
                reader.Close();
                cn.Close();
                cn.Open();
                sql = "select  *  from YeWuZiLiao where isnull(parentID,0)>0 and  mingcheng like '%" + chaxunwenzi + "%'";
                //dataconn.WriteLogclass(sql);
                myCommand.CommandText = sql;
                reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                
                while (reader.Read())
                {
                    @jieguo = jieguo + "<a href='" + urltou + "/wap/yewuziliao.aspx?id=" + reader["id"].ToString() + "'>" + reader["mingcheng"].ToString() + "</a>\n\n";
                }
            }
        }



        cn.Close();
        return jieguo;
    }
    public int bangdingshu(string weixinhao)//查找已绑定记录数记录
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select  count(*) as jl from jibenzhiliao where weixinghao='" + weixinhao + "'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        int jieguo = 0;
        //WriteLog("执行完成" + sql);



        while (reader.Read())
        {
            jieguo = Convert.ToInt32(reader["jl"].ToString());



        }
        cn.Close();
        return jieguo;
    }

    public string chatingshui(string weixinhao)//查找所在区域停水通知
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select   distinct tongzhineirong,wenbenriqi  from tingshuitongzhi where DateDiff(day,riqi,getdate())<30 and  quruid in (select quyu from jibenzhiliao where weixinghao='" + weixinhao + "') order by wenbenriqi desc";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = jieguo + "通知内容：" + reader["tongzhineirong"].ToString() + "\n发布日期" + reader["wenbenriqi"].ToString() + "\n\n";
        }
        cn.Close();
        return jieguo;
    }
    public string chatingshuisy(string weixinhao)//查找所有停水通知
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select  distinct tongzhineirong,wenbenriqi  from tingshuitongzhi where DateDiff(day,riqi,getdate())<30  order by wenbenriqi desc";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        string jieguo = "";
        //WriteLog("执行完成" + sql);

        while (reader.Read())
        {
            jieguo = jieguo + "通知内容：" + reader["tongzhineirong"].ToString() + "\n发布日期" + reader["wenbenriqi"].ToString() + "\n\n";
        }
        cn.Close();
        return jieguo;
    }
    public string shifouguanzhu(string weixinhao)//是否关注里面有数据
    {
        SqlConnection cn = dataconn.getcon();
        cn.Open();

        string sql = "select  * from guanzhuqingkuang where weixinghao='" + weixinhao + "'";
        SqlCommand myCommand = new SqlCommand(sql, cn);

        SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

        if (reader.Read())
        {

            cn.Close();
            return "a";
        }
        else
        {
            datacom.eccom("insert into guanzhuqingkuang(weixinghao,zhuixingbiaozhi,guanzhushijian) values ('" + weixinhao + "','0',getdate())");

            cn.Close();
            return "b";
        }

    }

}

